package indi.zhifa.study2024.nbr.logic.test.service.impl;

import com.alibaba.fastjson2.JSON;
import indi.zhifa.study2024.nbr.logic.test.entity.AuthObject;
import indi.zhifa.study2024.nbr.logic.test.entity.TestWhoImIResponse;
import indi.zhifa.study2024.nbr.logic.test.service.IWhoImIService;
import indi.zhifa.study2024.nbr.properties.AppProperties;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.Base64;

@RequiredArgsConstructor
@Component
public class WhoImIServiceImpl implements IWhoImIService {

    private final AppProperties mAppProperties;

    @Override
    public TestWhoImIResponse whoImI(String pAuthHeader) {
        TestWhoImIResponse testWhoImIResponse = new TestWhoImIResponse();
        testWhoImIResponse.setServName(mAppProperties.getServName());
        byte[] authArr = Base64.getDecoder().decode(pAuthHeader);
        AuthObject authObject = JSON.parseObject(authArr).to(AuthObject.class);
        testWhoImIResponse.setAuthObject(authObject);
        return testWhoImIResponse;
    }
}
